-
-
Notifications
You must be signed in to change notification settings - Fork 737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix] Prevent multiline values in short TextInputs #2789
Conversation
src/Discord.Net.Core/Entities/Interactions/MessageComponents/ComponentBuilder.cs
Outdated
Show resolved
Hide resolved
@@ -1415,6 +1418,9 @@ public string Value | |||
throw new ArgumentOutOfRangeException(nameof(value), $"Value must not be longer than {MaxLength ?? LargestMaxLength}."); | |||
if (value?.Length < (MinLength ?? 0)) | |||
throw new ArgumentOutOfRangeException(nameof(value), $"Value must not be shorter than {MinLength}"); | |||
if (Style == TextInputStyle.Short && value?.Contains('\n') == true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This validation shouldn't be placed in the property setter, as it might be used before setting the style of the text input.
It should be added to the Build()
method instead, this way we can be sure the style is set to the right value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to Build method
src/Discord.Net.Core/Entities/Interactions/MessageComponents/ComponentBuilder.cs
Outdated
Show resolved
Hide resolved
…omponentBuilder.cs
Description
When creating a Modal TextInput with the style Short and setting the value to a multi-line string, the error received will say just "Invalid Form Body", without exact feedback to the developer what the issue is.
This will cause an error:
Changes
In TextInputBuilder we check if the value set is a multi-line string by checking the presence of
\n
and if the Style is short we throw a ArgumentException.Currently it would still be possible to cause this error by doing the following step:
Additional checks could be set if requested to the setter of TextInputStyle property